/*控制导航菜单栏的显示与隐藏*/
$("#menu").on("tap", function(){
	if($("#menulist").css("display") == "none") {
		$("#menulist").slideDown();
	}
	else {
		$("#menulist").slideUp();
	}
})
/*控制导航菜单栏的显示与隐藏*/


/*轮播图*/
$(function(){
	var containerwidth = $(".bannercontainer").width() + "px";
	$(".bannerlist li").css("width", containerwidth);
	$(".bannerlist").css("width", 4*$(".bannercontainer").width() + "px");

	var intervalId = setTimeout(bannermove, 3000);
	var index = 0;

	function bannermove() {
		index = index + 1;

		$(".bannerlist").css("transform", "translate("+ -$(".bannercontainer").width()*index +"px)");
		$(".bannerlist").css("transition", "all 1500ms");

		$(".bannerlist")[0].addEventListener("webkitTransitionEnd", function() {
			if(index == 3) {
				index = 0;
				$(".bannerlist").css("transform", "translate(0px)");
				$(".bannerlist").css("transition", "all 0ms");
			}
			clearTimeout(intervalId);
			intervalId = setTimeout(bannermove, 3000);
		})
	}

	/*touchstart touchmove  touchend*/

	var startPoint = 0;
	$(".bannercontainer")[0].addEventListener("touchstart", function(e) {
		clearTimeout(intervalId);
		$(".bannerlist").css("transition", "all 0ms");
		startPoint = e.changedTouches[0].pageX;
		startEle = $(".bannerlist")[0].offsetLeft;
	})

	$(".bannercontainer")[0].addEventListener("touchmove", function(e) {
		var currPoint = e.changedTouches[0].pageX;
		var disX = currPoint - startPoint;
		var bannerleft = startEle + disX;
		$(".bannerlist").css("position", "relative");
		$(".bannerlist").css("left", bannerleft);
	})

	$(".bannercontainer")[0].addEventListener("touchend", function(e) {
		var bannerleft = parseFloat($(".bannerlist").css("left"));
		$(".bannerlist").css("left", "0px");
		$(".bannerlist").css("transform", "translate("+  (-$(".bannercontainer").width()*index + bannerleft)  +"px)");

		index =  parseInt(-(-$(".bannercontainer").width()*index + bannerleft)/$(".bannercontainer").width());
		intervalId = setTimeout(bannermove, 3000);

	})

	$(document).on("pageshow", "#homepage", function() {
		intervalId = setTimeout(bannermove, 3000);
	})

	$(document).on("pagebeforehide", "#homepage", function() {
		clearTimeout(intervalId);
	})


	// $(document).on("pageshow", "#homepage", function() {
	// 	intervalId = setTimeout(bannermove, 3000);
	// })

	// $(document).on("pagebeforehide","#homepage",function(){ // 当进入页面二时
	// 	clearTimeout(intervalId);
	// });

	$("#comment").on("tap", function() {
		$(".commentlist").css("display", "block");
		$(".commentlist").animate({
			"opacity": 1,
			"top": "0px"
		}, 500);
	})

	$("#commenthide").on("tap", function(){

		$(".commentlist").animate({
			"opacity": 0,
			"top": "300px"
		}, 500);
		setTimeout(function(){
			$(".commentlist").css("display", "none");
		}, 500)
	})

	
})

/*轮播图*/